import { createRouter, createWebHashHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import frame_routes from "@/router/frame"
import login_routes from "@/router/login"


const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: frame_routes.concat(login_routes)
})

// 使用钩子函数去校验是否登录
router.beforeEach((to,from)=>{
  // 判断用户是否登录 未登录重定向到登录页面
  const authStore = useAuthStore()
  if(!authStore.is_logined && to.name != 'login'){
    return {name:'login'}
  }
})

export default router
